package com.yuanyefu.ModifyDefinition;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

/**
 * Created by Administrator on 2017/9/16 0016.
 */
public class ChangeTypeBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        String[] beanNames = beanFactory.getBeanDefinitionNames();
        for (String beanName : beanNames){
            BeanDefinition bd = beanFactory.getBeanDefinition(beanName);
            if(bd.getBeanClassName().equals("com.yuanyefu.ModifyDefinition.BeanA")){
                bd.setBeanClassName("com.yuanyefu.ModifyDefinition.BeanB");
            }
        }
    }
}
